package org.ycx.doc.dao.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import org.ycx.doc.dao.auto.DocModuleMapper;
import org.ycx.doc.dao.model.DocModule;

import java.util.List;

/**
* DocModule 自定义Mapper
* Created by yang on 2017-08-30 17:02:41.
*/
public interface IDocModuleMapper extends DocModuleMapper {

    @Results({
            @Result(column="MODULE_ID", property="moduleId", jdbcType= JdbcType.INTEGER, id=true),
            @Result(column="APP_ID", property="appId", jdbcType=JdbcType.INTEGER),
            @Result(column="MODULE_NAME", property="moduleName", jdbcType=JdbcType.VARCHAR),
            @Result(column="MODULE_TYPE", property="moduleType", jdbcType=JdbcType.INTEGER),
            @Result(column="PID", property="pid", jdbcType=JdbcType.INTEGER),
            @Result(column="MODULE_CODE", property="moduleCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="M_VERSION", property="mVersion", jdbcType=JdbcType.INTEGER),
            @Result(column="CREATE_TS", property="createTs", jdbcType=JdbcType.DATE),
            @Result(column="CREATE_UID", property="createUid", jdbcType=JdbcType.INTEGER),
            @Result(column="UPDATE_TS", property="updateTs", jdbcType=JdbcType.DATE),
            @Result(column="UPDATE_UID", property="updateUid", jdbcType=JdbcType.INTEGER),
            @Result(column="STATES", property="states", jdbcType=JdbcType.INTEGER)
    })
    @Select ("select dm.* from doc_module dm,(select max(MODULE_ID) mid from doc_module where APP_ID=#{appId} and M_VERSION BETWEEN 1 and #{version} GROUP BY MODULE_CODE) dmc where dmc.mid = dm.module_id order by dm.MODULE_ID asc")
    List<DocModule> selectByAppIdAndVersion(@Param ("appId") Integer appId, @Param ("version") Integer version);

    @Results({
            @Result(column="MODULE_ID", property="moduleId", jdbcType= JdbcType.INTEGER, id=true),
            @Result(column="APP_ID", property="appId", jdbcType=JdbcType.INTEGER),
            @Result(column="MODULE_NAME", property="moduleName", jdbcType=JdbcType.VARCHAR),
            @Result(column="MODULE_TYPE", property="moduleType", jdbcType=JdbcType.INTEGER),
            @Result(column="PID", property="pid", jdbcType=JdbcType.INTEGER),
            @Result(column="MODULE_CODE", property="moduleCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="M_VERSION", property="mVersion", jdbcType=JdbcType.INTEGER),
            @Result(column="CREATE_TS", property="createTs", jdbcType=JdbcType.DATE),
            @Result(column="CREATE_UID", property="createUid", jdbcType=JdbcType.INTEGER),
            @Result(column="UPDATE_TS", property="updateTs", jdbcType=JdbcType.DATE),
            @Result(column="UPDATE_UID", property="updateUid", jdbcType=JdbcType.INTEGER),
            @Result(column="STATES", property="states", jdbcType=JdbcType.INTEGER)
    })
    @Select ("select dm.* from doc_module dm,(select max(MODULE_ID) mid from doc_module where APP_ID=#{appId} and M_VERSION = 0 GROUP BY MODULE_CODE) dmc where dmc.mid = dm.module_id order by dm.MODULE_ID")
    List<DocModule> selectByAppIdNoVersion(@Param ("appId") Integer appId);
}